//package com.hmall.common.aop;
//
//import com.hmall.common.utils.UserContext;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.amqp.core.Message;
//import org.springframework.stereotype.Component;
//
//@Aspect
//@Component
//@Slf4j
//public class RabbitConsumerAspect {
//
//    @Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener)")
//    public Object setUserContextFromHeader(ProceedingJoinPoint joinPoint) throws Throwable {
//        Object[] args = joinPoint.getArgs();
//        try {
//            for (Object arg : args) {
//                if (arg instanceof Message) {
//                    Message message = (Message) arg;
//                    Long userId = (Long) message.getMessageProperties().getHeaders().get("user-info");
//                    if (userId != null) {
//                        UserContext.setUser(userId);
//                    }
//                    break;
//                }
//            }
//            return joinPoint.proceed();
//        } finally {
//            UserContext.removeUser();
//        }
//    }
//}
